package com.gz.purchase.library.listener;

import com.gz.purchase.library.util.Constants;
import com.gz.purchase.library.util.CrashHandler;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 移库出库确认 界面 确认或拒绝某记录
 * author wanner1991
 */
public abstract class RejectOrAgreeInStorageListener extends BaseListener{
    private String TAG = RejectOrAgreeInStorageListener.class.getSimpleName();
    @Override
    public void onNoMoreData() {

    }

    @Override
    public void onOffline() {

    }

    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        try {
            String msg = response.getString(Constants.REQ_MSG);
            int status = response.getInt(Constants.REQ_STATUS);
            CrashHandler.i(TAG,response.toString());
            CrashHandler.i(TAG,"移库出库确认 界面 确认或拒绝某记录msg="+msg);
            CrashHandler.i(TAG,"移库出库确认 界面 确认或拒绝某记录status="+status);
            switch (status){
                case Constants.REQ_OK:
                    onResponsessSuccess();
                    break;
                case Constants.REQ_REJECT_FAIL:
                    onRejectFail(msg);
                    break;
                case Constants.REQ_AGREE_FAIL:
                    onAgreeFail(msg);
                    break;
                default:
                    onResponseFailed();
            }
        } catch (JSONException e) {
            onFailure(statusCode, headers, e, new JSONObject());
        }
    }

    public abstract void onResponsessSuccess();
    public abstract void onRejectFail(String msg);// 拒绝失败
    public abstract void onAgreeFail(String msg); // 同意失败
    @Override
    public void onFailure(int statusCode, Header[] headers,
                          Throwable throwable, JSONObject errorResponse) {
        CrashHandler.e(throwable);
        onResponseFailed();
    }
}
